/*
 *  Features.cpp
 *  Groove-ProjStudio
 *
 *  Created by Kai Sheng on 2/14/12.
 *  Copyright 2012 Georgia Tech. All rights reserved.
 *
 */

#include "Features.h"
#include <math.h>
#define MAXNOTE 1

double IOI_hist_entropy(double *IOIs, int notenum, int bins)
{
	int count=0;
	int interval = MAXNOTE/bins;
	double *distr = new double[bins];
	int total = 0;
	double entropy=0;
	
	for (int n=0; n<notenum; n++) { //counting
		while( IOIs[n] > count * interval)
		{
			if (IOIs[n] < (count+1)*interval) {
				distr[count]++;
			}
			else {
				count++;
			}
		}
	}
	
	for (int i=0; i<bins; i++)  //get total to normalize
		total += distr[i];
	for (int i=0; i<bins; i++)  //entropy calc
	{
		distr[i] /=total;
		entropy += distr[i] * log(distr[i]);
	}
	
	delete distr;
	return -entropy;
}

double VeloSum(double *velocity, int notenum)
{
	double sum = 0;
	for (int n=0; n<notenum; n++) {
		sum += velocity[n];
	}
	return sum;
}


